package com.tgy.thread;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Semaphore;

/**
 * @Author: tgy
 * @Date: 12/2/20 2:47 PM
 */
public class CyclicBarrierDemo {

    public static void main(String[] args) {

        CyclicBarrier cyclicBarrier = new CyclicBarrier(10, () -> {

            System.out.println("放行");
        });

        for (int i = 0; i < 100; i++) {

            final  int j = i;
            new Thread(()->{

                try {

                    cyclicBarrier.await();
                    System.out.println("i:" + j);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            },"t" + j).start();
        }


        Semaphore semaphore = new Semaphore(5);

    }
}
